package com.ss.android.common.util;

import android.content.Context;

import com.bytedance.common.utility.Logger;

import java.util.Properties;

public class TtProperties {
    private Properties mProperties;
    private static TtProperties instance;

    private TtProperties(Context arg4) {

        this.mProperties = new Properties();
        try {
            this.mProperties.load(arg4.getApplicationContext().getAssets().open("ss.properties"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public final String getString(String key, String fallback) {
        Object v4;
        Object v0 = this.readKey(key);
        if ((v0 instanceof String)) {
            v4 = v0;
        } else {
            v4 = fallback;
        }
        return ((String) v4);
    }

    public static TtProperties getInstance(Context context) {
        if (instance == null) {
            synchronized (TtProperties.class) {
                if (instance == null) {
                    instance = new TtProperties(context);
                }
            }
        }

        return instance;
    }

    public final Object readKey(String key) {
        Object value;
        try {
            if (this.mProperties.containsKey(key)) {
                value = this.mProperties.get(key);
            } else {
                value = null;
            }
            if (Logger.debug()) {
                Logger.d("TtProperties", key + " = " + value);
            }
            return value;
        } catch (Exception ex) {
          return null;
        }
    }
}

